package com.hlkj.baojin.constant.global_exception;

import com.hlkj.baojin.utils.bean.JsonResult;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 异常处理
 * Created by lzx on
 */
@RestController
public class FinalExceptionHandler implements ErrorController {
    @Override
    public String getErrorPath() {
        return "/error";
    }

    @RequestMapping(value = "/error")
    public ResponseEntity<JsonResult> error(HttpServletResponse resp) {
        String errMassage = "";
        // 错误处理逻辑
        switch (resp.getStatus()) {
            case 403:
                errMassage = "没有权限,登录超时";
                break;
            case 404:
                errMassage = "路径异常";
                break;


        }
        return ResponseEntity.ok(JsonResult.error(resp.getStatus(), errMassage));
    }
}